package 个人.wangxiao;


import cn.tedu.boke.portal.model.Post;
import cn.tedu.boke.portal.service.IPostService;
import cn.tedu.boke.portal.vo.PostLabelsVo;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 帖子 前端控制器
 * </p>
 *
 * @author tedu.cn
 * @since 2021-11-01
 */
@RestController
@RequestMapping("/boke/post")
public class PostController
{
    @Autowired
    private IPostService postService;

    @GetMapping("/labels")
    public PageInfo<PostLabelsVo> posts(Integer pageNum)
    {
        Integer pageSize = 8;
        if (pageNum == null)
        {
            pageNum = 1;
        }
        PageInfo<PostLabelsVo> pageInfo = postService.postLabels(pageNum, pageSize);
        return pageInfo;
    }

    @GetMapping("/labels/one/{id}")
    public PostLabelsVo onePost(@PathVariable Integer id)
    {
        PostLabelsVo onePost = postService.onePost(id);
        return onePost;
    }




    @GetMapping("/my")
    //获取当前用户所有帖子
    public List<Post> my(
            @AuthenticationPrincipal UserDetails user
            ){
        List<Post> posts = postService.getMyPoset(user.getUsername());


        return posts;
    }



}
